import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/base/base_state.dart';
import 'package:flutter_app/contract/login_contract.dart';
import 'package:flutter_app/res/colours.dart';
import 'package:flutter_app/routers/router_utils.dart';
import 'package:oktoast/oktoast.dart';
class LoginPage extends BaseFulWidget {
  @override
  _LoginPageState createState() {
    return _LoginPageState();
  }
}

class _LoginPageState extends BaseState<LoginPresenter, LoginPage>
    with SingleTickerProviderStateMixin
    implements ILoginView {
  TextEditingController _phoneController;
  TextEditingController _pwdController;

  @override
  void initState() {
    super.initState();
    _phoneController = TextEditingController();
    _pwdController = TextEditingController();
  }

  @override
  void dispose() {
    _phoneController.dispose();
    _pwdController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SingleChildScrollView(
        child: SafeArea(
          child: Container(
            alignment: Alignment.center,
            child: Column(
              children: [
                SizedBox(height: 10),
                Text('登录',
                    style: TextStyle(
                        fontSize: 16,
                        color: Colors.black,
                        fontWeight: FontWeight.w600)),
                Padding(
                  padding: const EdgeInsets.only(top: 40, left: 28),
                  child: SizedBox(
                    width: MediaQuery.of(context).size.width,
                    child: Text('请输入手机号',
                        style: TextStyle(
                            fontSize: 32,
                            color: Colors.black,
                            fontWeight: FontWeight.w400)),
                  ),
                ),
                Padding(
                    padding:
                        const EdgeInsets.only(left: 28, right: 28, top: 130),
                    child: TextField(
                      controller: _phoneController,
                      decoration: InputDecoration(hintText: '请输入手机号'),
                    )),
                Padding(
                    padding:
                        const EdgeInsets.only(top: 20, left: 28, right: 28),
                    child: TextField(
                      controller: _pwdController,
                      decoration: InputDecoration(
                          hintText: '请输入密码',
                          suffixIcon: Icon(Icons.remove_red_eye)),
                    )),
                //登录按钮
                Padding(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 28, vertical: 20),
                  child: SizedBox(
                      width: MediaQuery.of(context).size.width,
                      height: 42,
                      child: ElevatedButton(
                        child: Text(
                          '登录',
                          style: TextStyle(fontSize: 16, color: Colors.white),
                        ),
                        style: ButtonStyle(
                            //背景颜色
                            backgroundColor:
                                MaterialStateProperty.all(Colours.ff0692ff)),
                        //点击事件
                        onPressed: () {
                          // 取消焦点
                          FocusScope.of(context).requestFocus(FocusNode());
                          presenter.login(_phoneController.value.text,
                              _pwdController.value.text);
                        },
                      )),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  @override
  LoginPresenter createPresenter() => LoginPresenter(this);

  @override
  void loginSuccess() {
    showToast('登录成功');
    RouterUtils.goBack(context);
  }
}
